/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package psexecute;
import java.net.*;
import java.io.*;
import java.util.StringTokenizer;


/**
 *
 * @author rootx76
 */
public class Email {
//dichiaro attributi classe
static BufferedReader in;
static PrintWriter out;
static String server="mail.zucchettiproject.com";
static String mittente="francesco.gerrana@zucchettiproject.com";
static String destinatario="francesco.gerrana@zucchettiproject.com";
static String messaggio="questa e una email di prova";

public static void main(String[] args)
{
try
{
Socket s = new Socket(server, 25);
out = new PrintWriter(s.getOutputStream());
in = new BufferedReader(new InputStreamReader(s.getInputStream()));

String hostName = InetAddress.getLocalHost().getHostName();

receive();
send("Hostname " + hostName);
receive();
send("FROM: <" + mittente + ">");
receive();
send("TO: <" + destinatario + ">");
receive();
send("DATA");
receive();
StringTokenizer tokenizer = new StringTokenizer(messaggio, "\n");
while (tokenizer.hasMoreTokens())
send(tokenizer.nextToken());
send(".");
receive();
s.close();
}
catch (IOException exception)
{
System.out.println("Error: " + exception);
}
}

public static void send(String s) throws IOException
{
System.out.println(s);
System.out.println("\n");
out.print(s);
out.print("\r\n");
out.flush();
}

public static void receive() throws IOException
{
String line = in.readLine();
if (line != null)
{
System.out.println(line);
System.out.println("\n");
}
}

}
